package com.choosefine.it.company.controller;

import com.choosefine.it.common.def.CommonConstant;
import com.choosefine.it.common.utils.StringUtils;
import com.choosefine.it.common.utils.URLHandlerUtils;

import com.choosefine.it.manager.model.dto.ManagerFindprojectInfoDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.base.dto.PageDTO;
import com.choosefine.it.basedata.model.UserInfo;
import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.common.json.JsonUtil;
import com.choosefine.it.common.model.CustomRestTemplate;
import com.choosefine.it.common.utils.DateUtils;
import com.choosefine.it.company.model.CompanyFindManagerInfo;
import com.choosefine.it.company.model.CompanyManagerCollection;
import com.choosefine.it.company.model.ManagerContractorInfo;
import com.choosefine.it.company.model.vo.ProjectManagerRandomKeyVO;
import com.choosefine.it.company.service.CompanyFindManagerService;
import com.choosefine.it.company.service.CompanyManagerCollectionService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.google.gson.Gson;


/**
 * 建筑公司找项目承包人
 * @author chenjian
 * @date 2016-12-3 上午9:43:51
 */
@RestController
@RequestMapping("/companyFindManager")
@Api(value="建筑公司-找项目承包人",description="俞鑫")/*yuxin 3.9 all*/
public class CompanyFindManagerController extends BaseController{
	@Autowired
	private CompanyFindManagerService companyFindManagerService;
	@Autowired
	private CompanyManagerCollectionService companyManagerCollectionService;
	@Autowired
	CustomRestTemplate restTemplate;
	@Autowired
	ObjectMapper jsonObjectMapper;
	Logger logger=LoggerFactory.getLogger(CompanyFindManagerController.class);
	@Value("#{yaml.get('basedata.userinfo.getUserByUserCode')}")
	String userinfoURL=null;
	
	@ApiOperation(value = "建筑公司-找项目承包人列表和搜索",response=CompanyFindManagerInfo.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "expectProjectTypeId", value = "期望工程类型id", required = false, dataType = "String", paramType = "query"),
			@ApiImplicitParam(name = "areaCode", value = "班组期望的工作地区省或市id", required = false, dataType = "String", paramType = "query"),
			@ApiImplicitParam(name = "random", value = "工程类别名称/项目承包人姓名", required = false, dataType = "String", paramType = "query"),
			@ApiImplicitParam(name = "pageNum", value = "起始行", required = true, dataType = "int", paramType = "query"),
			@ApiImplicitParam(name = "pageSize", value = "一页显示的行数", required = true, dataType = "int", paramType = "query")})
	@RequestMapping(value="/getManagerList",method=RequestMethod.GET)
	public String getManagerList(
			@RequestParam(required = false) String expectProjectTypeId,
			@RequestParam(required = false) String areaCode,
			@RequestParam(required = false) String random,
			@RequestParam Integer pageNum,
			@RequestParam Integer pageSize){
		String result=null;
		Map<String, Object> params = new HashMap<>();
		params.put("expectProjectTypeId",expectProjectTypeId);
		params.put("areaCode",areaCode);
		params.put("random",random);
		PageDTO page= new PageDTO();
		page.setPageNum(pageNum);
		page.setPageSize(pageSize);
		Page<CompanyFindManagerInfo> list = companyFindManagerService.companyFindManagerList(params, page);
		result= responseSuccess(list);
		return result;
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@ApiOperation(value = "建筑公司-项目承包人的详情页", notes = "该用户的项目经验需要去调用项目经理manager下的项目经验接口",response=ManagerFindprojectInfoDTO.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userCode", value = "建筑公司的userCode", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "uuid", value = "建筑公司的uuid", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "publishId", value = "发布的ID", required = true, dataType = "Integer", paramType = "path")
	})
	@RequestMapping(value="/getManagerDetail/{userCode}/{uuid}/{publishId}",method=RequestMethod.GET)
	public String getManagerDetail(@PathVariable String userCode,@PathVariable String uuid,@PathVariable Integer publishId) throws JsonProcessingException{
		String result=null;
		Map<String, Object> params = new HashMap<>();
		params.put("userCode", userCode);
		params.put("uuid",uuid);
		params.put("publishId", publishId);
		params.put("type",CommonConstant.COMPANY_COLLECT_MANAGER);/*6代表建筑公司收藏项目经理发布找项目*/
		ManagerFindprojectInfoDTO managerFindprojectInfoDTO = companyFindManagerService.findCompanyFindManagerInfoById(params);
		result=responseSuccess(managerFindprojectInfoDTO);
		return result;
		
	}
	@ApiOperation(value = "建筑公司-收藏项目承包人")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userCode", value = "建筑公司的userCode", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "uuid", value = "建筑公司的uuid", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "publishId", value = "发布的ID", required = true, dataType = "Integer", paramType = "path")
	})
	@RequestMapping(value="/collectManager/{userCode}/{uuid}/{publishId}",method=RequestMethod.POST,produces = "application/json")
	public String collectManager(@PathVariable String userCode,@PathVariable String uuid,@PathVariable Integer publishId){
		String result=null;
		Map<String, Object> params = new HashMap<>();
		params.put("userCode", userCode);
		params.put("uuid",uuid);
		params.put("publishId", publishId);
		params.put("type",CommonConstant.COMPANY_COLLECT_MANAGER);/*6代表建筑公司收藏项目经理发布找项目*/
		params.put("ctime",System.currentTimeMillis());
		int num=companyFindManagerService.companyCollectionManager(params);
		if(num>0){
			result=responseSuccess(num);
		}else {
			result=responseFail(CommonConstant.COLLECT_DATA_EXISTS);
		}
		return result;
	}

	@ApiOperation(value = "建筑公司-取消收藏项目承包人")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userCode", value = "建筑公司的userCode", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "uuid", value = "建筑公司的uuid", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "publishId", value = "发布的ID", required = true, dataType = "Integer", paramType = "path")
	})
	@RequestMapping(value="/cancelCollectManager/{userCode}/{uuid}/{publishId}",method=RequestMethod.PUT,produces = "application/json")
	public String cancelCollectManager(@PathVariable String userCode,@PathVariable String uuid,@PathVariable Integer publishId){
		String result=null;
		Map<String, Object> params = new HashMap<>();
		params.put("userCode", userCode);
		params.put("uuid",uuid);
		params.put("publishId", publishId);
		params.put("type",CommonConstant.COMPANY_COLLECT_MANAGER);/*6代表建筑公司收藏项目经理发布找项目*/
		params.put("utime",System.currentTimeMillis());
		int num=companyFindManagerService.cancelCollectionManager(params);
		if(num>0){
			result=responseSuccess(num);
		}else {
			result=responseFail(CommonConstant.CANCEL_DATA_EXISTS);
		}
		return result;
	}

	@ApiOperation(value = "建筑公司-收藏项目承包人列表",response=CompanyFindManagerInfo.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userCode", value = "建筑公司的userCode", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "uuid", value = "建筑公司的uuid", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "pageNum", value = "起始行", required = true, dataType = "Integer", paramType = "query"),
			@ApiImplicitParam(name = "pageSize", value = "一页显示的行数", required = true, dataType = "Integer", paramType = "query")
	})
	@RequestMapping(value="/collectManagerList/{userCode}/{uuid}",method=RequestMethod.GET,produces = "application/json")
	public String collectManagerList(@PathVariable String userCode,@PathVariable String uuid,
										@RequestParam Integer pageNum,@RequestParam Integer pageSize){
		String result=null;
		Map<String, Object> params = new HashMap<>();
		params.put("userCode", userCode);
		params.put("uuid",uuid);
		params.put("type",CommonConstant.COMPANY_COLLECT_MANAGER);/*6代表建筑公司收藏项目经理发布找项目*/
		params.put("pageNum",pageNum);
		params.put("pageSize",pageSize);
		Page<CompanyFindManagerInfo> page=companyFindManagerService.collectManagerList(params);
		result=responseSuccess(page);
		return result;
	}
}
